home *** CD-ROM | disk | FTP | other *** search
- Path: news.sover.net!news
- From: mountain@sover.net (Steve Mount)
- Newsgroups: comp.lang.c
- Subject: Re: Converting Strings to Upper Case
- Date: 17 Mar 1996 14:29:55 GMT
- Organization: SoVerNet, Inc.
- Message-ID: <4ih7l3$526@thrush.sover.net>
- References: <4ifra6$52i@scipio.cyberstore.ca>
- NNTP-Posting-Host: pm0a12.mid.sover.net
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In article <4ifra6$52i@scipio.cyberstore.ca>, ejw@news.cyberstore.ca says...
- >I need to write a function to convert a string containg upper or lower case
- >characters to the opposite case. Something like:
- >
- > void libConvertUpperCase(char *str); and
- > void libConvertLowerCase(char *str);
- >
- >and the string would be modified. I just can't seem to wrap my head around
- >the best way that I know is better than writing a for loop to check each
- >element in the array?
-
- My home compiler has strlwr and strupr functions. At work, we don't, so
- just to make it work, quick and dirty, I did:
-
- void strnlwr(char *buffer, int len)
- {
- register int i;
- for (i=0;i<len;i++) buffer[i] = tolower(buffer[i]);
- return;
- }
-
- Note I added a length checker, as this was required; it may not be the most
- efficient, but it gets the job done. It also prevents me from duplicating
- the code that tolower/toupper does.
-
- +============================================================================+
- | Steve Mount, Software Engineer Work: sjjm@hawkeye.idx.com |
- | CIS: 73720,3404 MSN: S_Mountain Home: mountain@sover.net |
- | AOL: Mountain |
- | WWW: http://www.sover.net/~mountain/ "Fight, Win, Prevail!" |
- +============================================================================+
-
-